/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package br.ufc.quixada.adrs.service;

import br.ufc.quixada.adrs.dao.EnderecoDAO;
import br.ufc.quixada.adrs.model.Endereco;
import br.ufc.quixada.adrs.util.Msg;
import br.ufc.quixada.adrs.util.UtilAdrs;
import java.sql.SQLException;
import java.util.List;
import org.slf4j.LoggerFactory;

/**
 *
 * @author Caio
 */
public class EnderecoService {

    private final EnderecoDAO dao = new EnderecoDAO();

    public boolean insertEndereco(Endereco endereco) {
        try {
            UtilAdrs.upperCase(endereco);
            dao.insert(endereco);
            return true;
        } catch (SQLException ex) {
            LoggerFactory.getLogger(this.getClass()).error(Msg.EXCEPTION_MESSAGE, this.getClass().getSimpleName(), ex);
            return false;
        }
    }

    public boolean updateEndereco(Endereco endereco) {
        try {
            UtilAdrs.upperCase(endereco);
            dao.update(endereco);
            return true;
        } catch (SQLException ex) {
            LoggerFactory.getLogger(this.getClass()).error(Msg.EXCEPTION_MESSAGE, this.getClass().getSimpleName(), ex);
            return false;
        }
    }

    public boolean deleteEndereco(Long id) {
        try {
            dao.delete(id);
            return true;
        } catch (SQLException ex) {
            LoggerFactory.getLogger(this.getClass()).error(Msg.EXCEPTION_MESSAGE, this.getClass().getSimpleName(), ex);
            return false;
        }
    }

    public Endereco getEnderecoById(Long id) {
        try {
            Endereco end = dao.getById(id);
            return end;
        } catch (SQLException ex) {
            LoggerFactory.getLogger(this.getClass()).error(Msg.EXCEPTION_MESSAGE, this.getClass().getSimpleName(), ex);
            return null;
        }
    }

    public List<Endereco> getEnderecosByEventoId(Long id) {
        try {
            List<Endereco> end = dao.getByEventoId(id);
            return end;
        } catch (SQLException ex) {
            LoggerFactory.getLogger(this.getClass()).error(Msg.EXCEPTION_MESSAGE, this.getClass().getSimpleName(), ex);
            return null;
        }
    }

    public List<Endereco> getAllEnderecos() {
        try {
            List<Endereco> end = dao.getAll();
            return end;
        } catch (SQLException ex) {
            LoggerFactory.getLogger(this.getClass()).error(Msg.EXCEPTION_MESSAGE, this.getClass().getSimpleName(), ex);
            return null;
        }
    }
}
